import pandas as pd


def get_can_20ms_list(df_can_20ms_adas_list,nsecs):
    # 找到最接近目标值的行数据
    closest_data = min(df_can_20ms_adas_list, key=lambda x: abs(x[2] - nsecs))

    # 打印结果
    return  closest_data







if __name__ == '__main__':
    df_can_100ms_save_path="./test/ST_Upload_100ms_t.json"
    df_can_20ms_save_path="./test/ST_Upload_20ms_t.json"
    try:
        df_can_100ms_function_adas = pd.read_json(df_can_100ms_save_path, lines=True)
    except Exception as e:
        print('data report read error, ', str(e))

    try:
        df_can_20ms_function_adas = pd.read_json(df_can_20ms_save_path, lines=True)
    except Exception as e:
        print('data report read error, ', str(e))

    df_can_100ms_function_adas_list = df_can_100ms_function_adas[
        ['start_time_str', 'path', 'nsecs','ADCS8_ACCState'
         ]].values.tolist()

    df_can_20ms_function_adas_list = df_can_20ms_function_adas[
        ['start_time_str', 'path', 'nsecs','SuppressReason'
         ]].values.tolist()

    ADCS8_ACCState_last=df_can_100ms_function_adas_list[0][3]
    for row in df_can_100ms_function_adas_list:
        start_time_str=row[0]
        nsecs=row[2]
        ADCS8_ACCState=row[3]

        if start_time_str=="2024-01-10 14:15:45" and ADCS8_ACCState_last==2 and ADCS8_ACCState==6:
            data_list=get_can_20ms_list(df_can_20ms_function_adas_list,nsecs)
            SuppressReason=data_list[3]
            print(SuppressReason)
        ADCS8_ACCState_last=ADCS8_ACCState